package com.personalsystem.tool.util;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
import java.util.Properties;

public class ReadProperties {
	
	public String read(String property){
		InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("jdbc.properties");   
		  Properties p = new Properties();   
		  try {   
		   p.load(inputStream);   
		  } catch (IOException e1) {   
		   e1.printStackTrace();   
		  }   
		  String value=p.getProperty(property);
		  try {
			inputStream.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		  return value;
	}
	
	public void write(String property,String value){
		ClassLoader loader=this.getClass().getClassLoader();
		InputStream inputStream = loader.getResourceAsStream("jdbc.properties");   
		URL url=loader.getResource("jdbc.properties");
		  Properties props = new Properties();
		  try {
	            props.load(inputStream);
	            // ���� Hashtable �ķ��� put��ʹ�� getProperty �����ṩ�����ԡ�
	            // ǿ��Ҫ��Ϊ���Եļ��ֵʹ���ַ�����ֵ�� Hashtable ���� put �Ľ��
	            OutputStream fos = new FileOutputStream(url.getFile());            
	            props.setProperty(property,value);
	            // ���ʺ�ʹ�� load �������ص� Properties ���еĸ�ʽ��
	            // ���� Properties ���е������б?���Ԫ�ضԣ�д�������
	            props.store(fos, "Update '" + property + "' value");
	        } catch (IOException e) {
	            System.err.println("�����ļ����´���");
	        }
	}
	
	public static void main(String[] args) {
		System.out.println(new ReadProperties().read("sms.extendCallmdn"));
	}

}
